define(["app",
        "js/resources/sys/selects/SelectsResource",
        "js/services/MessageBox"],
    function (app) {
        var deps = ["$scope", "$rootScope", "$state", "$stateParams", "$modal", "MessageBox", "SelectsResource"];

        function controller ($scope, $rootScope, $state, $stateParams, $modal,
                             MessageBox, SelectsResource) {
            var id = $stateParams.id;
            $scope.dataSelectsList = [];

            //查询树形菜单主表
            $scope.querySelectsData = function () {
                $scope.searchSelectObj = {
                    xxName: ""
                };
                showLoading();
                var queryObj = {};
                angular.extend(queryObj, $scope.searchSelectObj); //将查询条件和分页控件对象，合并为一个请求对象给request
                SelectsResource.searchSelects(queryObj).success(function (rep) {
                    hideLoading();
                    $scope.dataSelectsList = $scope.dataSelectsList = rep.data;

                    $rootScope.ispublic = $scope.dataSelectsList[0].isPublic;
                    $rootScope.Remark = $scope.dataSelectsList[0].remark;

                    $state.go("treePage.treeItemList", {
                        "id": $scope.dataSelectsList[0].id,
                        "treeName": $scope.dataSelectsList[0].treeName,
                        "enterType": $scope.global_listPage_enterType_menu
                    });
                });
            };
            $scope.querySelectsData();

            $scope.treeItemList = function (idstr) {

                var id = idstr.id;
                var selecttreeName = "";
                var selectRemark = "";

                for (var i = 0; i < $scope.dataSelectsList.length; i++) {
                    if ($scope.dataSelectsList[i].id == id) {
                        selecttreeName = $scope.dataSelectsList[i].treeName
                        $rootScope.ispublic = $scope.dataSelectsList[i].isPublic;
                        $rootScope.Remark = $scope.dataSelectsList[i].remark;
                        break;
                    }
                }

                $(".treeItem").removeClass("active");

                $state.go("treePage.treeItemList", {
                    "id": id,
                    "treeName": selecttreeName,
                    "enterType": $scope.global_listPage_enterType_menu

                });
            }
        }

        controller.$inject = deps;
        app.lazy.controller("treePageController", controller);
    });